#ifndef MTKTET_GAME_H
#define MTKTET_GAME_H

#include "allegro.h"

#ifndef NDEBUG
# define DEBUG_MSG(MSG) (std::cout << (MSG) << std::endl);
#else
# define DEBUG_MSG(MSG) ((void)0)
#endif

// class that initializes whole Game
class Game
{
 public:
    Game (int x = 800, int y = 600) { init (); set_mode (x, y); }
    virtual ~Game () { close (); }

    // main loop of the game
    void run (void) {
        while (! game_end) {
            /* game loop */
        }
    }

    // sets screen width and height
    bool set_mode (int x, int y) {
        // value different then 0 means that there was an error
        if (set_gfx_mode (GFX_AUTODETECT, x, y, 0, 0)) {
            std::cout << "Error: " << allegro_error << std::endl;
            close ();
        }
        DEBUG_MSG ("set_mode: OK");
    }


 private:
    // if the flag is set to true the game will end
    bool game_end;
    std::string error_message;

    void init () {
        DEBUG_MSG("Initialization");
        // initializing allegro library
        allegro_init ();
        install_keyboard ();
        game_end = false;
    }

    void close () {
        DEBUG_MSG ("Deinitialization");
        // deinitializing allegro library
        allegro_exit ();
    }
};



class Block
{
 public:
    Block (int _posx, int _posy, int _velocity) {
        posx = _posx;
        posy = _posy;
        velocity = _velocity;
        block_bitmap = NULL;
    }

    virtual ~Block () { close (); }
    // returning pointer to the bitmap tha represent single element of the block
    const BITMAP* get_bitmap (void) const {
        return block_bitmap;
    }

 private:
    // don't create block with default constructor
    Block ();
    // position of the block on the board
    int posx, posy;
    // velocity of the block falling down
    int velocity;
    BITMAP *block_bitmap;

    void load_image (char *image) {
        block_bitmap = load_bitmap ("data/block.bmp", NULL);
    }

    void close () {
        if (block_bitmap) {
            destroy_bitmap (block_bitmap);
            block_bitmap = NULL;
        }
    }
};

#endif //MTKTET_GAME_H